# -*- coding: utf-8 -*-
# 操作内容：
# @Software: PyCharm
# @File: Buynow_api.py
# @Author: 一碗好酒（张智）
# @E-mail: 1473658931@qq.com, 
# @Time: 7月 08, 2021
# ---
import jsonpath

from api.base_api import BuyerBaseApi
from api.buyer.login_api import BuyerLoginApi
from common.client import RequestsClient


class BuyNowApi(BuyerBaseApi):
    def __init__(self):
        super().__init__()
        # self.host = 'http://www.mtxshop.com:7002'  # 继承基类
        self.url = self.host + '/trade/carts/buy'
        self.params={
            'sku_id': '891',
            'num': '1'
        }
        self.method = 'post'
        # self.headers = {
        #     'Authorization': RequestsClient.access_token  #公共引用token写在基类中。
        # }

if __name__ == '__main__':
    buyerapi = BuyerLoginApi()
    resp = buyerapi.send()
    # RequestsClient.access_token = jsonpath.jsonpath(resp.json(),'$.access_token')[0]  #jsonpath要练习
    BuyerBaseApi.buyer_token = jsonpath.jsonpath(resp.json(),'$.access_token')[0]  #jsonpath要练习

    resp = BuyNowApi().send()

    print(BuyNowApi().headers) #排查

    print(resp.status_code)